#!/usr/bin/bash
function usage() {
    echo "Usage: `basename $0` filename [interpreter path]"
    exit 0
}


if test "x$1" == "x"; then
    usage
fi

INTERPRETER="$( which bash 2>/dev/null)"

if test "x$2" != "x"; then
    if ! [ -r $2 ]; then
        echo "Error! Interpreter \"$2\" not found"
        usage
    else
        INTERPRETER="$2"
    fi
fi

if [ -r $1 ]; then
    echo "File $1 already present, opening"
    vim $1
    exit 0
fi

cat >$1 <<EOF
#!$INTERPRETER

EOF

chmod +x $1
vim $1 +2

